export const state = () => {
  return {
    fetching: false,
    data: []
  }
}

export const mutations = {
  updateFetching(state, action) {
    state.fetching = action
  },
  updateListData(state, action) {
    state.data = action.records
  }
}

export const actions = {
  fetchList({ commit }, params) {
    commit('updateFetching', true)
    return this.$axios.$post(`/links/list`, {
      page: 1,
      limit: 9999
    })
      .then(response => {
        commit('updateListData', response.result)
        commit('updateFetching', false)
        return Promise.resolve(response)
      })
      .catch(error => {
        commit('updateFetching', false)
        return Promise.reject(error)
      })
  }
}
